﻿using Entity.BaseInfo.DTO.Department;
using Entity.BaseInfo.View.Department;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service.BaseInfo;

namespace AnQinManagermentBackendAPI.Controller.BaseInfo
{
    /// <summary>
    /// 部门表
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class DepartmentController : ControllerBase
    {
        /**
         * 部门业务接口
         */
        private readonly DepartmentService _departmentService;

        /**
         * 构造函数注入
         */
        public DepartmentController(DepartmentService departmentService)
        {
            _departmentService = departmentService;
        }

        /// <summary>
        /// 获取部门列表
        /// </summary>
        /// <param name="departmentSearchDTO"></param>
        [HttpGet]
        [ProducesResponseType(typeof(DepartmentView), 200)]
        public async Task<IActionResult> GetDepartmentList([FromQuery] DepartmentSearchDTO departmentSearchDTO)
        {
            var response = await _departmentService.GetDepartmentList(departmentSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增部门
        /// </summary>
        /// <param name="departmentAddDTO"></param>
        [HttpPost]
        public async Task<IActionResult> AddDepartment([FromBody] DepartmentAddDTO departmentAddDTO)
        {
            var response = await _departmentService.AddDepartment(departmentAddDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 更新部门
        /// </summary>
        /// <param name="departmentUpdateDTO"></param>
        [HttpPut]
        public async Task<IActionResult> PutDepartment([FromBody] DepartmentUpdateDTO departmentUpdateDTO)
        {
            var response = await _departmentService.PutDepartment(departmentUpdateDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除部门
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> DeleteDepartment([FromQuery] string Id)
        {
            var response = await _departmentService.DeleteDepartment(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 获取部门列表
        /// </summary>
        /// <param name="departmentSelectSearchDTO"></param>
        [HttpGet("Select")]
        [ProducesResponseType(typeof(DepartmentSelectView), 200)]
        public async Task<IActionResult> GetDepartmentList([FromQuery] DepartmentSelectSearchDTO departmentSelectSearchDTO)
        {
            var response = await _departmentService.GetDepartmentSelectList(departmentSelectSearchDTO);
            return StatusCode(response.Status, response);
        }
    }
}
